<template>
  <view class="merchantRecommendation">
    <text class="title">活动中心</text>
    <view class="content">
      <view class="around-tab">
        <view
          v-for="(item, index) in menulist"
          :key="index"
          :class="`around-tab__item ${typeId == item._id ? 'active' : ''}`"
          @tap="typeId = item._id"
          ><text>{{ item.name }}</text
          ><view v-show="typeId == item._id" class="line" />
        </view>
      </view>
    </view>
    <view>
      <activity-card
        v-for="(item, index) in datalist"
        :key="index"
        class="card"
        :data="item"
      />
    </view>

    <view class="bottom" @tap="loadMore">更多资讯>></view>
  </view>
</template>

<script>
import "./index.scss";
import Taro from "@tarojs/taro";
import icon1 from "../../../../assets/icon/icon1.png";
import img1 from "../../../../assets/image/build1.png";
import activityCard from "../../../../components/activityCard/index";
import requset from "../../../../utils/request";
import apis from "../../../../utils/aips";

export default {
  components: {
    "activity-card": activityCard,
  },

  data() {
    return {
      msg: "Hello33333 world!",
      img1: img1,
      typeId: "",
      datalist: [],
      menulist: [],
    };
  },

  watch: {
    // 如果 `question` 发生改变，这个函数就会运行
    typeId: function (newQuestion, oldQuestion) {
      this.getArticlesList(newQuestion)
    }
  },

  created() {
    // requset("get", "/api/rest/articles.htm");
  },
  mounted() {
    this.getArticlesCategory();
    // this.getArticlesList();
  },

  methods: {
    getArticlesCategory() {
      requset("get", "/api/rest/articles_category.htm").then((res) => {
        this.typeId = res._list[0]._id;
        this.menulist = res._list;
      });
    },

    getArticlesList(id) {
      requset("get", "/api/rest/articles.htm", {
       q_category_id: id,
        row_limit: 4, //每页记录数，非必填
        p: 1,
      }).then((res) => {
        console.log(res._list);
        // this.menulist = res._list
        this.datalist = res._list;
        // _id title face_image_id
      });
    },

    loadMore() {
      console.log("222");
      Taro.navigateTo({
        url: `/pages/culture/index?typeId=${this.typeId}`,
      });
    },
  },

  // setCurrent(x) {
  //   console.log('x')
  //   this.current=x
  // },
};
</script>
